package com.hll.spring_book.service.log;

import com.hll.spring_book.mapper.log.LogMapper;
import com.hll.spring_book.pojo.Log;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Logs)表服务实现类
 *
 * @author makejava
 * @since 2021-04-20 21:42:58
 */
@Service("logService")
public class LogServiceImpl implements LogService {
  @Resource private LogMapper logMapper;

  /**
   * 通过ID查询单条数据
   *
   * @param id 主键
   * @return 实例对象
   */
  @Override
  public Log queryById(Integer id) {
    return this.logMapper.queryById(id);
  }

  /**
   * 查询多条数据
   *
   * @param offset 查询起始位置
   * @param limit 查询条数
   * @return 对象列表
   */
  @Override
  public List<Log> queryAllByLimit(int offset, int limit) {
    return this.logMapper.queryAllByLimit(offset, limit);
  }

  /**
   * 新增数据
   *
   * @param logs 实例对象
   * @return 实例对象
   */
  @Transactional(
      propagation = Propagation.REQUIRED,
      isolation = Isolation.DEFAULT,
      timeout = 36000,
      rollbackFor = Exception.class)
  @Override
  public Log insert(Log logs) {
    this.logMapper.insert(logs);
    return logs;
  }

  /**
   * 修改数据
   *
   * @param logs 实例对象
   * @return 实例对象
   */
  @Transactional(
      propagation = Propagation.REQUIRED,
      isolation = Isolation.DEFAULT,
      timeout = 36000,
      rollbackFor = Exception.class)
  @Override
  public Log update(Log logs) {
    this.logMapper.update(logs);
    return this.queryById(logs.getId());
  }

  /**
   * 通过主键删除数据
   *
   * @param id 主键
   * @return 是否成功
   */
  @Transactional(
      propagation = Propagation.REQUIRED,
      isolation = Isolation.DEFAULT,
      timeout = 36000,
      rollbackFor = Exception.class)
  @Override
  public boolean deleteById(Integer id) {
    return this.logMapper.deleteById(id) > 0;
  }

  @Override
  public List<Log> queryAll(Log log) {
    return this.logMapper.queryAll(log);
  }
}
